package cn.hxt.basic.service.impl;

import cn.hxt.basic.mapper.BaseMapper;
import cn.hxt.basic.query.BaseQuery;
import cn.hxt.basic.service.IBaseService;
import cn.hxt.basic.util.PageList;
import cn.hxt.org.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
//@Service  不要添加
@Transactional(readOnly = true , propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    @Transactional
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.loagAll();
    }

    @Override
    public T queryById(Long id) {
        return mapper.loagById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery Query) {
        //获取条数
        Long cunt = mapper.queryCunt(Query);
        //获取当前页数据1
        List<T> data = mapper.queryData(Query);
        //自接还回对象
        return new PageList<T>(cunt,data);
    }

    @Override
    @Transactional
    public void batchRemove(List<Long> ids) {
        mapper.batchRemove(ids);
    }
}
